﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using Converter;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;
using System.Resources;
using System.Reflection;
using ConfigurationNghiepVu;

namespace csla4Skeleton.UI.SL.NghiepVu.TienMat.TM_PhieuChi
{
    public partial class FormNguoiNop : ChildWindow
    {
        public object model;
        public NghiepVuType type;
        TM_PhieuChi_ChildWindow tm_PhieuChi_ChildWindow;
        public FormNguoiNop(object model, NghiepVuType type)
        {        
            LocalizationConverter converter = new LocalizationConverter();
            converter.LocalResourceManager = new ResourceManager("csla4Skeleton.UI.SL.NghiepVu.MuaSanPham.MSP_MuaHangHoa.Resources", Assembly.GetExecutingAssembly());
            this.Resources.Add("Localization", converter);
            InitializeComponent();
            this.type = type;
            this.model = model;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {

            string nguoiNop = this.NguoiNopTextBox.Text;
            tm_PhieuChi_ChildWindow = new TM_PhieuChi_ChildWindow(nguoiNop, this.model, this.type);
            tm_PhieuChi_ChildWindow.Show();

            tm_PhieuChi_ChildWindow.Visibility = Visibility.Collapsed;
            this.OKItemButton.IsEnabled = false;
            this.CancelItemButton.IsEnabled = false;

            tm_PhieuChi_ChildWindow.LapPhieuChiCompleteted += new EventHandler(OnLapPhieuChiCompleteted);
            tm_PhieuChi_ChildWindow.OnClosedChildWindow += new EventHandler(OnClosedWindow);

        }

        private void OnClosedWindow(object sender, EventArgs e)
        {
            this.Close();
        }
        private void OnLapPhieuChiCompleteted(object sender, EventArgs e)
        {
            
            if (tm_PhieuChi_ChildWindow.CountSave == 0)
            {

                MessageBoxResult result = MessageBox.Show("Bạn có muốn xem phiếu chi ?", "Xem phiếu chi", MessageBoxButton.OKCancel);

                if (result == MessageBoxResult.OK)
                {
                    tm_PhieuChi_ChildWindow.Visibility = Visibility.Visible;
                    tm_PhieuChi_ChildWindow.CountSave++;

                }
                else
                {
                    tm_PhieuChi_ChildWindow.CountSave++;
                    tm_PhieuChi_ChildWindow.Close();
                }
            }
            else
            {
                tm_PhieuChi_ChildWindow.Close();
            }
           
        }

    }
}

